package com.novabluetooth.views.iknetbluetoothlibrary;

import android.content.Context;
import android.util.Log;
import android.webkit.JavascriptInterface;
import com.health.db.DbManager;
import com.health.tablebean.BD_ORGANIZE_EMPLOYEE;
import com.health.viewscontrols.NovaApplication;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;

public class AndroidtoJs extends Object {

    Context context;
    public AndroidtoJs(Context context){
        this.context = context;
    }

    private DbManager dbmanger = null;
    @JavascriptInterface
    public String InsertSql(String text){
        Log.e("TAG","插入："+text);
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        System.out.println(text);
        dbmanger.addSF(text);
        return "success";
    }

    @JavascriptInterface
    public String getInfo(String sql){
        //冠心病
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray gxb = new JSONArray();
        try {
            gxb = dbmanger.getGXB(sql);
        }catch (Exception e){
            System.out.println("异常了："+e.toString());
        }
        return gxb.toString();
    }

    @JavascriptInterface
    public String getInfo2(String sql){
        //一般人群
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray ybrq = dbmanger.getYBRQ(sql);
        Log.e("TAG","大小："+ybrq.length());
        return ybrq.toString();
    }



    @JavascriptInterface
    public String getInfo3(String sql){
        //关节炎
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray gjy = dbmanger.getGJY(sql);
        Log.e("TAG","大小："+gjy.length());
        return gjy.toString();
    }

    @JavascriptInterface
    public String getInfo4(String sql){
        //类风湿关节炎
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray gjy = dbmanger.getLFSGJY(sql);
        Log.e("TAG","大小："+gjy.length());
        return gjy.toString();
    }

    @JavascriptInterface
    public String getInfo5(String sql){
        //老年慢性支气管炎
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray gjy = dbmanger.getLNMXZQGY(sql);
        Log.e("TAG","大小："+gjy.length());
        return gjy.toString();
    }

    @JavascriptInterface
    public String getInfo6(String sql){
        //慢阻肺
        dbmanger = ((NovaApplication) context.getApplicationContext()).getDbManger();
        Log.e("TAG","查询："+sql);
        JSONArray gjy = dbmanger.getMZF(sql);
        Log.e("TAG","大小："+gjy.length());
        return gjy.toString();
    }

    @JavascriptInterface
    public String getDcotor(){
        List<BD_ORGANIZE_EMPLOYEE> doctorList = NovaApplication.getDoctorList();
        JSONArray jsonArray = new JSONArray();

        for(BD_ORGANIZE_EMPLOYEE doctor:doctorList){
            JSONObject tmpObj = new JSONObject();
            try {
                tmpObj.put("name",doctor.getNAME());
                tmpObj.put("id",doctor.getUSER_ID());
            } catch (JSONException e) {
                e.printStackTrace();
            }

            jsonArray.put(tmpObj);
        }
        return jsonArray.toString();
    }
}
